﻿<cfsilent>
	<cfscript>
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		markAdvice = getProperty("serviceFactory").getBean("markAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		
		event.setArg("pageTitle", "成绩管理 - 成绩修订 - 查看学生成绩");
		
		studentId = event.getArg("STU");
		
		sql = "SELECT stu_name FROM t_student WHERE stu_id = :studentId ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
		
		rs_student = queryObj.execute( sql=sql ).getResult();
		
		sql = "SELECT 
					 t_teacher.tch_name, t_mark_aduit.op_ts, t_mark_aduit.op_ip, t_mark_aduit.operation 
				FROM 
					 t_mark_aduit 
					 INNER JOIN t_teacher ON t_teacher.tch_id = t_mark_aduit.tch_id 
				WHERE 
					 t_mark_aduit.stu_id = :studentId 
				ORDER BY 
					t_mark_aduit.opid DESC";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
		
		rs_studentMarkAduit = queryObj.execute( sql=sql ).getResult();
				
		
		sql = "SELECT 
					 t_term.academic_year, t_term.academic_term, 
					 t_course.course_name, t_course.course_credit, 
					 t_student_mark.retaking, t_student_mark.mark_mode, 
					 t_student_mark.mark_result, t_student_mark.mark_note, 
					 t_student_mark.mark_resit, t_student_mark.mark_renote, 
					 t_student_mark.mark_resit_limit, t_student_mark.credit,
					 t_student_mark.credit_point, 
					 t_student_mark.credit_point_o, 
					 t_course_prop.prop_id, t_course_prop.prop_name, 
					 t_student_mark.scm_id, t_term.term_id 
				FROM 
					 t_student_mark 
					 INNER JOIN t_term ON t_term.term_id = t_student_mark.term_id 
					 INNER JOIN t_course ON t_course.cid = t_student_mark.cid 
					 INNER JOIN t_course_prop ON t_course_prop.prop_id = t_student_mark.prop_id 
				WHERE 
					 t_student_mark.stu_id = :studentId 
				ORDER BY 
					 t_term.academic_year DESC , t_term.term_id, t_course_prop.prop_id, t_course.course_name ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
		
		rs_studentMark = queryObj.execute( sql=sql ).getResult();
		
		
		termYearArray = [];
		termArray = [];
		
		if ( rs_studentMark.recordCount ) {
			
			currentTab = event.getArg("TabID", "labMark" & rs_studentMark["academic_year"][1]);
			
			for ( k=1; k LTE rs_studentMark.recordCount; k++){ 
				termYear = [ rs_studentMark["academic_year"][k], 0 ];
				if ( not arrayFind( termYearArray, termYear ) ) {
					arrayAppend( termYearArray, termYear );
				}
			}
			
			i=0;
			for ( termYear in termYearArray ) {
				i++;
				for ( j=1; j LTE rs_studentMark.recordCount; j++){
					if ( rs_studentMark["academic_year"][j] eq termYear[1] ) {
						termYear[2] = termYear[2] + 1;
						termYearArray[i] = termYear;
					}
				}
			}

			
			for ( m=1; m LTE rs_studentMark.recordCount; m++){
				term = [ rs_studentMark["academic_year"][m], rs_studentMark["academic_term"][m], 0, rs_studentMark["term_id"][m] ];
				if ( not arrayFind( termArray, term ) ) {
					arrayAppend( termArray, term );
				}
			}

			i=0;
			for ( term in termArray ) {
				i++;
				for ( x=1; x LTE rs_studentMark.recordCount; x++){
					if ( rs_studentMark["academic_year"][x] eq term[1] and rs_studentMark["academic_term"][x] eq term[2] ) {
						term[3] = term[3] + 1;
						termArray[i] = term;
					}
				}
			}
			
		}else{
			currentTab = 'labNotFound';
		}
		
		passArgs = structNew();
		structInsert(passArgs, "STU", studentId, true);
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">成绩数据维护</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i>学生成绩 - <cfoutput>#rs_student.stu_name#</cfoutput>
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				
				<div class="UItab">
					<div class="tabLables">
                    	<cfif rs_studentMark.recordCount>
                            <cfloop array="#termYearArray#" index="termYear">
                                <span <cfif currentTab eq "labMark" & termYear[1]>class="active"</cfif> id="labMark<cfoutput>#termYear[1]#</cfoutput>" tabTarget="Mark<cfoutput>#termYear[1]#</cfoutput>"><cfoutput>#termYear[1]#</cfoutput> 学年</span>
                            </cfloop>
                        <cfelse>
                        	<span <cfif currentTab eq "labNotFound">class="active"</cfif> id="labNotFound" tabTarget="NotFound">没有成绩数据</span>
                        </cfif>
						<cfif rs_studentMarkAduit.recordCount>
							<span <cfif currentTab eq "labMarkAduit">class="active"</cfif> id="labMarkAduit" tabTarget="MarkAduit">成绩变更日志</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
                <cfif rs_studentMark.recordCount>
	
					<!--- 隐藏删除 --->
					<form id="formRemove" class="hidden_elem" method="post" action="<cfoutput>#buildURL('studentMarkBatchRemoveDo')#</cfoutput>">
						<textarea id="deleteSMIDs" name="SMIDs"></textarea>
					</form>
				
					<cfloop array="#termYearArray#" index="termYear">
					
						<div id="Mark<cfoutput>#termYear[1]#</cfoutput>" class="tabContent">
						
							<div class="noticeBlock">
                                   	<div class="operation">
                                             <a class="uiButton" target="_blank" href="<cfoutput>#buildURL('totalScorePrint', passArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText"><b>打印成绩汇总表</b></span></a>
                                        </div>
								<h3><cfoutput>#termYear[1]#</cfoutput> 学年 共计 <span class="number bold"><cfoutput>#termYear[2]#</cfoutput></span> 门课程</h3>
							</div>
						
							<cfloop array="#termArray#" index="term">
							
								<cfif term[1] eq termYear[1]>
									
									<div class="noticeBlock">
										<div class="operation">
											<cfset structInsert( passArgs, "TID", term[4], true ) />
											<a class="uiButton" href="javascript:batchRemove('<cfoutput>#term[4]#</cfoutput>');"><i class="mrs img btnClear"></i><span class="uiButtonText">批量删除成绩</span></a>
											<a class="uiButton " href="<cfoutput>#buildURL('studentMarkCreate', passArgs)#</cfoutput>"><i class="mrs img btnAdd"></i><span class="uiButtonText">添加成绩</span></a>
                                                       &nbsp;<a class="uiButton" target="_blank" href="<cfoutput>#buildURL('gradeScorePrint', passArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText">打印成绩通知单</span></a>
											<cfset structDelete( passArgs, "TID", false ) />
										</div>
										<h3><cfoutput>#dictAdvice.getTerm( term[2] )#</cfoutput></h3>
										<hr/>
									</div>
								
									<cfset row = 0 />
								
									<table class="UIEditable" data-target="<cfoutput>#term[4]#</cfoutput>">
										<thead>
											<tr>
												<td width="18"></td>
												<td>课程</td>
												<td align="center" width="40">学分</td>
                                                            <td align="center" width="50">成绩绩点</td>
                                                            <td align="center" width="50">学分绩点</td>
												<td align="center" width="60">课程性质</td>
												<td align="center" width="60">正考</td>
												<td align="center" width="60">补考</td>
												<td width="18"></td>
											</tr>
										</thead>
										<tbody>
                                            <cfloop query="rs_studentMark">
											
												<cfif term[1] eq rs_studentMark.academic_year and term[2] eq rs_studentMark.academic_term >
												
													<cfset row++ />
                                                                 
                                                                 <cfif rs_studentMark.mark_mode eq '5' >
														<cfset finalResult = rs_studentMark.mark_result />
                                                                      <cfset resitResult = rs_studentMark.mark_resit />
                                                                 <cfelse>
                                                                      <cfset finalResult = markAdvice.getMark( rs_studentMark.mark_mode, rs_studentMark.mark_result, rs_studentMark.mark_note ) />
                                                                      <cfset resitResult = markAdvice.getMarkResit( rs_studentMark.mark_mode, rs_studentMark.mark_resit, rs_studentMark.mark_renote, rs_studentMark.mark_resit_limit ) />
                                                                  </cfif>
												
													<cfset structInsert(passArgs, "SMID", rs_studentMark.scm_id, true) />
												
													<tr class="editRows <cfif rs_studentMark.credit eq 0 OR rs_studentMark.credit_point eq 0 OR rs_studentMark.credit_POINT_o eq 0>alertRow2</cfif>">
                                                                 	<cfif rs_studentMark.mark_mode eq '5'>
                                                                      	<td><a href="javascript:void(0);"></a></td>
                                                                      <cfelse>
															<td><a href="javascript:void(0);" class="stat no marktrigger" data-rowid="<cfoutput>#rs_studentMark.scm_id#</cfoutput>"></a></td>
                                                                     	</cfif>
														
														<td><cfoutput>#rs_studentMark.course_name#</cfoutput> <cfif rs_studentMark.retaking>(重修)</cfif></td>
														<td align="center"><span class="numeric"><cfoutput>#numberFormat( rs_studentMark.credit, "_._" )#</cfoutput></span></td>
                                                                      <td align="center"><span class="numeric"><cfoutput>#numberFormat( rs_studentMark.credit_point, "_._" )#</cfoutput></span></td>
                                                                      <td align="center"><span class="numeric"><cfoutput>#numberFormat( rs_studentMark.credit_point_o, "_._" )#</cfoutput></span></td>
														<td align="center"><cfoutput>#rs_studentMark.prop_name#</cfoutput></td>
														<td align="center"><cfif isNumeric(finalResult)><span class="numeric"><cfoutput>#finalResult#</cfoutput></span><cfelse><cfoutput>#finalResult#</cfoutput></cfif></td>
														<td align="center"><cfif isNumeric(resitResult)><span class="numeric"><cfoutput>#resitResult#</cfoutput></span><cfelse><cfoutput>#resitResult#</cfoutput></cfif></td>
                                                                      <cfif rs_studentMark.mark_mode eq '5'>
                                                                      	 <td><a onclick="javascript:showLock();" class="stat locked" title="老系统数据，这儿不支持修改"></a></td>
                                                                      <cfelse>
															<td><a class="edit" href="<cfoutput>#buildURL('studentMarkModify', passArgs)#</cfoutput>"></a></td>
                                                                     	</cfif>
													</tr>
												</cfif>
											
											</cfloop>
											<cfset structDelete( passArgs, "SMID", false ) />
									</table>
								
								</cfif>
						
							</cfloop>
						</div>
						
					</cfloop>
			
					<script language="javascript" type="text/javascript">
						
						
						//<![CDATA[
						<!--
						function showLock(){
							alert("这个是老系统迁移数据，为了保证数据和类型的准确性，暂不支持前台修改和删除！\n（如果需要修改，请联系技术人员后台修改）");
						}
						
						function batchRemove(targetId) {
							
							var markIds = [];
							
							$("table[data-target='" + targetId + "'] a.marktrigger.yes").each(function(index, element) {
								markIds.push( $(this).attr("data-rowid") );
							});
							if (markIds.length) {
								$("#deleteSMIDs").val( markIds.join("|") );
								/* 提交删除请求 */
								$("#formRemove").submit();
							}
							else {
								alert("请选择要删除的成绩项");
							}
							return void(0);
						}
						
						$(document).ready(function() {
						
							$("table[data-target] a.markall").click(function(){
								var $trigger = $(this);
							
								var targetId = $trigger.attr("data-target");
							
								var status = $trigger.hasClass("yes");
								var newStatus = true;
							
								/* 切换状态数据 */
								if (status) {
									newStatus = false;
								}
								
								if ( newStatus ) { 
									$("table[data-target='" + targetId + "'] a.marktrigger").removeClass("no").addClass("yes");
									$trigger.removeClass("no").addClass("yes");
								} 
								else { 
									$("table[data-target='" + targetId + "'] a.marktrigger").removeClass("yes").addClass("no"); 
									$trigger.removeClass("yes").addClass("no"); 
								}
								
							});
						
							$("table[data-target] a.marktrigger").click(function(){
								var $trigger = $(this);
								
								var status = $trigger.hasClass("yes");
								var newStatus = true;
							
								/* 切换状态数据 */
								if (status) {
									newStatus = false;
								}
								if ( newStatus ) { 
									$trigger.removeClass("no").addClass("yes");
								} 
								else { 
									$trigger.removeClass("yes").addClass("no"); 
								}
							
							});
							
						});
							
						// -->
						//]]>				
					</script>
				
				<cfelse>
				
					<div id="NotFound" class="tabContent">
                    	<div class="noticeBlock">
							<div class="operation">
								<a class="uiButton " href="<cfoutput>#buildURL('studentMarkCreate',passArgs)#</cfoutput>"><i class="mrs img btnAdd"></i><span class="uiButtonText">添加成绩</span></a>
							</div>
							<h3>目前还没有成绩记录</h3>
							<hr/>
						</div>
                    </div>
					
				</cfif>
				
				<cfif rs_studentMarkAduit.recordCount>
					
					<div id="MarkAduit" class="tabContent">
						
						<div class="noticeBlock">
							<h3>成绩变更审计</h3>
						</div>
						
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td width="60">操作人</td>
									<td width="120">变更时间</td>
									<td width="120">IP地址</td>
									<td>内容</td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_studentMarkAduit">
									<cfset row ++ />
									<tr class="editRows">
										<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
										<td><cfoutput>#rs_studentMarkAduit.tch_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDateTimeString(rs_studentMarkAduit.op_ts, 'YYYY/MM/DD HH:MI')#</cfoutput></span></td>
										<td><span class="numeric"><cfoutput>#rs_studentMarkAduit.op_ip#</cfoutput></span></td>
										<td><cfoutput>#rs_studentMarkAduit.operation#</cfoutput></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
						
					</div>
					
				</cfif>
			
			</div>
		</li>
	</ul>
</div>